﻿using System;
using System.Windows.Forms;
using QUANLYSINHVIEN.Sevice;

namespace QUANLYSINHVIEN
{
    public partial class Form1 : Form
    {
        ISinhVienService sv = new ISinhVienService();
        ILopService hs = new ILopService();
        int dong;
        int id;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dtg_SinhVien.DataSource = ISinhVienService.LoadSinhVien();
            cbbcoloum.DataSource = hs.LoadLop();
            cbbcoloum.ValueMember = "MaLop";
            cbbcoloum.DisplayMember = "TenLop";
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            ISinhVienService.ThemSinhVien(txtMaSV.Text,txtTenSV.Text,txtLop.Text,txtDiaChi.Text);
            Form1_Load(sender, e);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtMaSV.Clear();
            txtTenSV.Clear();
            txtLop.Clear();
            txtDiaChi.Clear();
        }

        private void dtg_SinhVien_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dong = e.RowIndex;
            id = int.Parse(dtg_SinhVien.Rows[dong].Cells["dtg_id"].Value.ToString());            
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            sv.XoaSinhVien(id);
            Form1_Load(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            ISinhVienService.SuaSinhVien(id,txtMaSV.Text,txtTenSV.Text,txtLop.Text,txtDiaChi.Text);
            Form1_Load(sender, e);
        }

        private void btnLop_Click(object sender, EventArgs e)
        {
            frmLop frm = new frmLop();
            frm.Show();
        }

        private void dtg_SinhVien_TabIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Vừa thay đổi text");
        }

        private void dtg_SinhVien_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void dtg_SinhVien_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            MessageBox.Show("Vừa thay đổi text");
        }
    }
}
